package com.hardware.protocol;

import com.hardware.protocol.mqtt.MqttReciever;
import com.hardware.protocol.mqtt.MqttSender;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@SpringBootApplication
public class ProtocolApplication {

	@Resource
	private MqttSender mqttSender;

	@Resource
	private MqttReciever mqttReciever;

	public static void main(String[] args) {
		SpringApplication.run(ProtocolApplication.class, args);
	}
	@PostConstruct
	public void init() {
		// 模拟MQTT发送消息
		this.test_send();
	}

	public void test_send() {
		try {
			MqttSender myMqttClient = mqttSender;
			int i=0;
			while (true) {
				//topic一般包含设备ID
				myMqttClient.publishMessage("/mqtt/dev/dev00001", "hello"+i, 1);
				Thread.sleep(2500);
				i++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
